package org.jeecg.modules.zcgl.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.zcgl.entity.AssetInfoSub;
import org.jeecg.modules.zcgl.service.IAssetInfoSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
* @Description: 资产信息
* @Author: jeecg-boot
* @Date:   2020-06-19
* @Version: V1.0
*/
@Api(tags="资产信息明细")
@RestController
@RequestMapping("/zcgl/assetInfoSub")
@Slf4j
public class AssetInfoSubController/* extends JeecgBaseController<AssetInfoSub, AssetInfoSub, IAssetInfoSubService>*/ {

    @Autowired
    private IAssetInfoSubService assetInfoSubService;

    /**
     * 根据资产ID和明细的状态查询资产信息
     * @param assetInfoIds
     * @param roomStatus
     * @param req
     * @return
     */
//   @ApiOperation(value="资产明细查询", notes="资产明细-通主表ID查询")
    @GetMapping(value = "/queryAssetInfoSubByAssetIds")
    public Result<?> queryAssetInfoSubByAssetId(@RequestParam String assetInfoIds, @RequestParam(required = false) Integer roomStatus,
                                                HttpServletRequest req) {
        QueryWrapper<AssetInfoSub> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(AssetInfoSub::getAssetInfoId, assetInfoIds.split(CommonConstant.DEFAULT_SEPARATOR));
        queryWrapper.lambda().eq(roomStatus != null,AssetInfoSub::getRoomStatus, roomStatus);
        queryWrapper.select("id as value, room_name text");
        List<Map<String, Object>> assetInfoSubList = assetInfoSubService.listMaps(queryWrapper);
        return Result.ok(assetInfoSubList);
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "资产明细信息-通过id查询")
    @ApiOperation(value = "资产明细信息-通过id查询", notes = "资产明细信息-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        AssetInfoSub assetInfoSub = assetInfoSubService.getById(id);
        if (assetInfoSub == null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(assetInfoSub);
    }

    /**
     * 统计面积
     *
     * @param ids
     * @return
     */
//    @AutoLog(value = "资产信息-批量删除")
    @ApiOperation(value = "资产信息-统计面积", notes = "资产信息-统计面积")
    @GetMapping(value = "/queryTotalAreaByIds")
    public Result<?> queryTotalAreaByIds(@RequestParam(name = "ids", required = true) String ids) {
        BigDecimal totalArea = this.assetInfoSubService.queryTotalAreaByIds(ids);
        return Result.ok(totalArea);
    }

//    @Override
//    public List<AssetInfoSub> exportList(List<AssetInfoSub> list) {
//        return list;
//    }
//
//    @Override
//    public boolean importSave(AssetInfoSub assetInfoSub) {
//        return assetInfoSubService.save(assetInfoSub);
//    }
}
